using System.Net;
using System.Net.Sockets;

namespace Pinwheel.Kernel
{
    public interface ISocket
    {
        void StartReceive(SocketAsyncEventArgs e);
        void StartSend(SocketAsyncEventArgs e);
        
        void Close();
    }
    
    public interface IServerSocket : ISocket
    {
        void Listen(int port);
        void Listen(IPEndPoint endPoint);
        void Close(SocketAsyncEventArgs socketEvent);
    }
    
    public interface IClientSocket : ISocket
    {
    }

    public interface ISocketSession
    {
        ISocket Socket { get; }
        
        SocketAsyncEventArgs ReceiveEventArgs { get; }
        SocketAsyncEventArgs SendEventArgs { get; }
        
        SocketBuffer Received { get; }
        SocketBuffer Prepare { get; }
        
        void Accept(Socket socket);
        void Connect(Socket socket);
        void ConnectFailed();
        void Receive(Socket socket);
        void Send(byte[] data, int index = 0);
        void Sended(int size);
        void Error(Socket socket, SocketError error);
        void Close(Socket socket);
    }
    
    public interface ISocketSessionProvider
    {
        ISocketSession Create(ISocket socket, ISocketListener listener, SocketAsyncEventArgs receive, SocketAsyncEventArgs send, int bufferSize);
    }
}